package com.ruoyi.hotel.controller;

import java.util.List;
import java.util.Arrays;

import com.ruoyi.hotel.domain.bo.HmSupplyPurchaseBo;
import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.hotel.domain.vo.HmSupplyPurchaseVo;
import com.ruoyi.hotel.service.IHmSupplyPurchaseService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 实际采购
 *
 * @date 2023-10-30
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/hotel/supplyPurchase")
public class HmSupplyPurchaseController extends BaseController {

    private final IHmSupplyPurchaseService iHmSupplyPurchaseService;

    /**
     * 查询实际采购列表
     */
    @SaCheckPermission("hotel:supplyPurchase:list")
    @GetMapping("/list")
    public TableDataInfo<HmSupplyPurchaseVo> list(HmSupplyPurchaseBo bo, PageQuery pageQuery) {
        return iHmSupplyPurchaseService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出实际采购列表
     */
    @SaCheckPermission("hotel:supplyPurchase:export")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HmSupplyPurchaseBo bo, HttpServletResponse response) {
        List<HmSupplyPurchaseVo> list = iHmSupplyPurchaseService.queryList(bo);
        ExcelUtil.exportExcel(list, "【请填写功能名称】", HmSupplyPurchaseVo.class, response);
    }

    /**
     * 获取实际采购详细信息
     *
     * @param purchaseId 主键
     */
    @SaCheckPermission("hotel:supplyPurchase:query")
    @GetMapping("/{purchaseId}")
    public R<HmSupplyPurchaseVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long purchaseId) {
        return R.ok(iHmSupplyPurchaseService.queryById(purchaseId));
    }

    /**
     * 新增实际采购
     */
    @SaCheckPermission("hotel:supplyPurchase:add")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody HmSupplyPurchaseBo bo) {
        return toAjax(iHmSupplyPurchaseService.insertByBo(bo));
    }

    /**
     * 修改实际采购
     */
    @SaCheckPermission("hotel:supplyPurchase:edit")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody HmSupplyPurchaseBo bo) {
        return toAjax(iHmSupplyPurchaseService.updateByBo(bo));
    }

    /**
     * 删除实际采购
     *
     * @param purchaseIds 主键串
     */
    @SaCheckPermission("hotel:supplyPurchase:remove")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.DELETE)
    @DeleteMapping("/{purchaseIds}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] purchaseIds) {
        return toAjax(iHmSupplyPurchaseService.deleteWithValidByIds(Arrays.asList(purchaseIds), true));
    }

    /**
     * 新增实际采购(自动计算)
     * @param bo
     */

    @RepeatSubmit()
    @PostMapping("/purchaseTask")
    public void purchaseTask(@RequestBody HmSupplyPurchaseBo bo) {
        iHmSupplyPurchaseService.doPurchase(bo,getUserId());
    }

}
